package com.example.demo.sensitive.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @ClassName TaskStatusEnum
 * @Description 任务状态枚举
 * @Author System
 * @Date 2025/9/19
 **/
@Getter
@AllArgsConstructor
public enum TaskStatusEnum {

    PENDING("pending", "待执行"),
    RUNNING("running", "执行中"),
    COMPLETED("completed", "已完成"),
    FAILED("failed", "失败"),
    CANCELLED("cancelled", "已取消");

    private final String code;
    private final String desc;

    /**
     * 根据code获取枚举
     */
    public static TaskStatusEnum getByCode(String code) {
        for (TaskStatusEnum status : values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        return null;
    }

    /**
     * 判断是否为终止状态
     */
    public boolean isTerminal() {
        return this == COMPLETED || this == FAILED || this == CANCELLED;
    }

    /**
     * 判断是否为进行中状态
     */
    public boolean isProcessing() {
        return this == PENDING || this == RUNNING;
    }
}
